import matplotlib.pyplot as plt
import numpy as np

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

categories = ['A', 'B', 'C', 'D', 'E']
y1 = [25, 40, 30, 55, 15]
y2 = [15, 30, 35, 40, 30]

#生成与我们类别数量相等额整数序列
x = np.arange(len(categories))
width = 0.35#每一个柱子的宽度

plt.figure(figsize=(10, 6))
plt.bar(x - width / 2, y1, width, label='组1', color = 'skyblue')
plt.bar(x + width / 2, y2, width, label='组2', color = 'lightgreen')

#更改刻度
plt.xticks(x, categories)
plt.title('柱状图示例')
plt.xlabel('类别')
plt.ylabel('数值')
plt.legend()
plt.show()
